/*
 *  $Id: Shelter.cs 1221 2010-11-30 16:54:52Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Earth.Spells {
    public class Shelter: SelfEnchantmentCard {
        public Shelter(): base("001_e_s_shelter") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Earth;
            Value = 100;
            AddManaCost(ElementType.Earth, 4);
        }

        protected override void DoAction(TargetArgs<int> args) {
            foreach (Creature cr in args.Player.GetCreatures())
                if (cr.State == CreatureState.Offence) cr.State = CreatureState.Untapped;
            base.DoAction(args);
        }
        protected override EnchantmentAffect CreateEnchantment() {
            return new ShelterAffect();
        }

        private class ShelterAffect: EnchantmentAffect<Shelter> {
            public ShelterAffect() {
                Add(new TimeAffect(1, TimePhase.OwnOffence, new ShelterAura()));
            }

            public override bool Dispellable {
                get { return false; }
            }

            public override bool Drawable {
                get { return false; }
            }
        }

        private class ShelterAura: AuraAffect {
            public ShelterAura(): base(true, false) {}

            public override string Id {
                get { return AffectManager.GetCardId<Shelter>("aura"); }
            }

            public override int AverageWeightPercent {
                get { return 500; }
            }

            protected override bool AcceptAura(AbstractObject obj) {
                return AcceptOwner(obj) && (obj is Player || obj is Creature);
            }

            protected override Affect CreateSubAffect() {
                return new ShelterAuraAffect();
            }
        }

        private class ShelterAuraAffect: SpellAffect<Shelter> {
            public ShelterAuraAffect() {
                Add(new Affects.ModTakenDamage(DamageType.PhysicalAttack, -3));
                Add(new Affects.Antimagic());
                Add(new Affects.DisableAttack());
            }
        }
    }
}
